// promise.all    
// promise 数组，所有数组到了一起resolve
const p1 = new Promise((resolve) => resolve('p1完成'))   
const p2 = new Promise((resolve,reject) => {
    setTimeout(() => {
        resolve('p2延迟1秒')
    },1000)
})  

const p3 = new Promise((resolve,reject) => {
    setTimeout(() => {
        resolve('p3延迟2秒')
    },2000)
})  

Promise.Myall = (promises) => {
    let arr = [],
        count = 0;
    
        return new Promise((resolve,reject) =>{
            promises.forEach((item,i) => {
                Promise.resolve(item)  
                    .then(res => {
                        arr[i] = res;
                        count += 1;
                        if( count === promises.length) 
                        resolve(arr)
                    },reject)
            })
        })
}  

Promise.Myall([p1,p2,p3])  
    .then(res => {
        console.log(res);
    }) 
    .catch(err => {
        console.log(err)
    })